package cn.train.service;

import java.math.BigDecimal;
import java.sql.Time;

import org.apache.ibatis.session.SqlSession;

import cn.train.dao.IAddTrainDao;
import cn.train.util.SqlSessionFactoryUtil;

public class AddTrain {
	SqlSession session= SqlSessionFactoryUtil.getSqlSession();
	IAddTrainDao addTraindao = session.getMapper(IAddTrainDao.class);
	public int addtrain(String cname,String rnrs,String kclx,String qdz,String zdz,String cfsj,String dzsj,String cpjcj) {
		
		int rs=Integer.parseInt(rnrs);//容纳人数
		Time ctime=Time.valueOf(cfsj);
		Time dtime=Time.valueOf(dzsj);
		double jia1qian= Double.parseDouble(cpjcj);
		BigDecimal bigNum = new BigDecimal(jia1qian).setScale(2,BigDecimal.ROUND_HALF_UP);
		
		int addcar=addTraindao.addCar(cname, rs, kclx);
		int banci=addTraindao.ShowAddCarNum(cname);
		addTraindao.addCarpiao(qdz, zdz, ctime, dtime, rs, banci, bigNum);
		int sw=rs/9*2;
		int pt=rs/9*7;
		
		for(int i=1;i<=7;i++) {
		   addTraindao.AddZuoWei(sw,pt,banci,i);
		}
		session.commit();		
		return addcar;
	}

	public int lookcarname(String carname) {
		return addTraindao.lookcarname(carname);
	}
}
